package com.tutos;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.tutos.modules.GeneralModule;
import com.tutos.modules.GuiceServletModule;
import com.tutos.modules.MonitorModule;
import com.tutos.modules.ShiroConfigurationModule;
import com.tutos.modules.StudentModule;

/**
 * This class is the starting point of the application. It only forwards
 * 'requests' to other classes so things can start working!
 * 
 * @author Mo
 */

public class GuiceServletInjector extends GuiceServletContextListener {
	
	public static Injector injector = null;
	
	private ServletContext servletContext;
	
	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		servletContext = servletContextEvent.getServletContext();
		super.contextInitialized(servletContextEvent);
	}
	
	@Override
	protected Injector getInjector() {
		if(injector == null)
			injector = Guice.createInjector(new ShiroConfigurationModule(servletContext), new GuiceServletModule(), new MonitorModule(), new StudentModule(), new GeneralModule());
		
		return injector;
	}
}
